package net.techwatch.gwt.mvp.client.view;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class MessageDisplayerWidget extends DialogBox implements MessageDisplayer.Display {

	private Button closeButton = new Button("Close");
	private HTML serverResponseLabel = new HTML();
	
	public MessageDisplayerWidget() {
		setText("Remote Procedure Call");
		setAnimationEnabled(true);

		// We can set the id of a widget by accessing its Element
		closeButton.getElement().setId("closeButton");
		final Label textToServerLabel = new Label();
		VerticalPanel dialogVPanel = new VerticalPanel();
		dialogVPanel.addStyleName("dialogVPanel");
		dialogVPanel.add(new HTML("<b>Sending name to the server:</b>"));
		dialogVPanel.add(textToServerLabel);
		dialogVPanel.add(new HTML("<br><b>Server replies:</b>"));
		dialogVPanel.add(serverResponseLabel);
		dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
		dialogVPanel.add(closeButton);
		setWidget(dialogVPanel);

		// Add a handler to close the DialogBox
		/*closeButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				dialogBox.hide();
			}
		});*/

		setText("Remote Procedure Call");
		serverResponseLabel
				.removeStyleName("serverResponseLabelError");
		//serverResponseLabel.setHTML(e.getMsg());
		center();
		closeButton.setFocus(true);
		hide();
	}
	
	@Override
	public HasClickHandlers getCloseButton() {
		return closeButton;
	}
	
	public Widget getWidget() {
		return this;
	}

	@Override
	public HasHTML getContent() {
		return serverResponseLabel;
	}

}
